package com.example.freemarker.template;

import com.example.annotations.Autowired;
import com.example.annotations.Compontent;
import com.example.flowable.model.FlowableModel;
import com.example.flowable.model.FormModel;
import com.example.flowable.model.TableModel;
import com.example.flowable.service.FlowableModelService;
import com.example.flowable.service.FormModelService;
import com.example.flowable.service.TableModelService;
import com.example.freemarker.config.DirectiveHandler;
import com.example.freemarker.config.FreemarkerCompontent;
import com.example.freemarker.config.TemplateDirective;

import java.util.HashMap;
import java.util.Map;

/**
 * @Classname ProcessModelTemplate
 * @Description TODO
 * @Date 2022/9/4 13:27
 * @Created by XiongXiong
 * @Author: X.I.O
 */
@FreemarkerCompontent("ProcessModel")
@Compontent
public class ProcessModelTemplate extends TemplateDirective {

    @Override
    public String getName() {
        return "ProcessModel";
    }

    @Autowired
    private FormModelService formModelService;

    @Autowired
    private FlowableModelService flowableModelService;

    @Autowired
    private TableModelService tableModelService;

    @Override
    public void execute(DirectiveHandler handler) throws Exception {
        String id=handler.getString("id");
        FlowableModel flowableModel=flowableModelService.getById(id);
        Integer formId=flowableModel.getFromId();
        TableModel tableModel=tableModelService.getById(formId);
        Map<String,Object> map=new HashMap<>();
        map.put("tableName",tableModel.getTableName());
        map.put("processdefid",flowableModel.getProcessdefid());
        map.put("formhtml",tableModel.getFormhtml());
        handler.put(RESULT,map).render();
    }
}
